package com.pubg.vo;

import java.util.List;

/**
 * 视图层的分页Bean
 */
public class PageVo<T>{
    private int currPageNo;//当前页码
    private int pageSize=1; // 每页数量
    private int totalCount; // 数据总量
    private int totalPageCount; //总页数
    private List<T> dataList; // 数据列表

    public PageVo() {
    }

    public PageVo(String currPageNo, String pageSize, int totalCount) {
        this.setPageSize(pageSize);
        this.setTotalCount(totalCount);
        this.setCurrPageNo(currPageNo);
    }

    public int getCurrPageNo() {
        return currPageNo;
    }

    /**
     * 设置当前页码
     * 不能小于1  不能大于总页码
     * @param currPageIndex
     */
    public void setCurrPageNo(String currPageIndex) {
        if (currPageIndex == null){
            this.currPageNo = 1;
            return;
        }
        int currPageNo = Integer.parseInt(currPageIndex);
        if (currPageNo<=1){
            this.currPageNo=1;
            return;
        }
        if (currPageNo>=this.getTotalPageCount()){
            this.currPageNo=this.getTotalPageCount();
            return;
        }
        this.currPageNo = currPageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(String pageSize) {
        if (pageSize == null){
            return;
        }
        this.pageSize =Integer.parseInt(pageSize);
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        if (totalCount > 0 && pageSize > 0){
            this.totalPageCount = totalCount % pageSize == 0
                    ?(totalCount/pageSize):(totalCount/pageSize)+1;
        }
        this.totalCount = totalCount;
    }

    public int getTotalPageCount() {
        return totalPageCount;
    }

    public List<T> getDataList() {
        return dataList;
    }

    public void setDataList(List<T> dataList) {
        this.dataList = dataList;
    }



}
